<template>
<div>
    <div id="relevantPolicy" style="width: 900px;height: 900px;">

    </div>
</div>
</template>

<script>
import echarts from "echarts";
//import registerMap from 'jquery'
import axios from "axios";
import { postAjax, getAjax } from "../../../api/api.js";
export default {
  name: "",
  props: ["id"],
  data() {
    return {
      
      charts: "",
      // name:'',

        name:"",
        children: []
    };
  },
  methods: {
    //相关政策
    // name= sessionStorage.getItem(title),
    
    querypolicys(baseId,title) {
      //   console.log(title)
      this.name = title;
//      alert(title)
      let url = JSON.stringify({ id: baseId });
      getAjax("/policyInfo/list/querypolicys/" + url).then(response => {
        if (response.data.code === 0) {
          this.isLoading = false;
          this.querypolicysData = response.data.obj;
//          this.chartData.name = response.data.obj.title;
          let _this = this;
          if(this.querypolicysData){
             this.children = [];
            this.querypolicysData.forEach(element => {
            _this.children.push({ name: element.policyTitle });
          });
          }else{
            this.children = [{name:"231312"}];
          }
         
          this.showTree("relevantPolicy");
        } else {
          this.$Message.warning("数据请求异常");
        }
      });
    },
    showTree(id) {
      this.charts = echarts.init(document.getElementById(id));
      this.charts.setOption({
        tooltip: {
          trigger: "item",
          triggerOn: "mousemove"
        },
        series: [
          {
            type: "tree",
            data: [{
              name:this.name,
              children:this.children
            }],
            top: "20",
            left: "25%",
            bottom: "10%",
            right: "70%",

            symbolSize: 7,

            label: {
              normal: {
                position: "left",
                verticalAlign: "middle",
                align: "right",
                fontSize: 12,
                backgroundColor: "#f6f6f6",
                borderWidth: "1",
                borderRadius: "10",
                padding: [10, 10, 10, 10],
                color: "#333"
              }
            },
            leaves: {
              label: {
                normal: {
                  position: "right",
                  verticalAlign: "middle",
                  align: "left"
                }
              }
            },

            expandAndCollapse: false,
            animationDuration: 550,
            animationDurationUpdate: 750
          }
        ]
      });
      //});
    }
  },
  //调用
  created() {
    // this.querypolicys();
  },
  mounted() {
    // console.log(this.baseId)
  }
};
</script>
<style>
</style>
